package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.TRole;
import com.dk.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("role")
public class RoleController {

    @Reference
    private RoleService roleService;

    @RequestMapping("show")
    public String toShow(){
        return "role/show";
    }

    @RequestMapping("getInfo")
    @ResponseBody
    public List<TRole> getInfo(){
        List<TRole> list = roleService.getInfo();
        return list;
    }

    @RequestMapping("toAdd")
    public String toAdd(){
        return "role/add";
    }

    @RequestMapping("addInfo")
    @ResponseBody
    public boolean addInfo(TRole role,Integer[] menuId){
        return roleService.addInfo(role,menuId);
    }

    @RequestMapping("deleteById")
    @ResponseBody
    public boolean deleteById(Integer roleId){
        return roleService.deleteById(roleId);
    }

    @RequestMapping("toUpdate")
    public String toUpdate(@RequestParam("roleId")Integer roleId, Model model){
        TRole role = roleService.getInfoById(roleId);
        model.addAttribute("role",role);
        return "role/update";
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public Boolean updateInfo(TRole role, @RequestParam("menuId")Integer[] menuId){
        Boolean b = roleService.updateInfo(role,menuId);
        return b;
    }
}
